package com.itbour.service.trade.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.common.util.StringUtils;
import com.itbour.dao.trade.BuyTmplDao;
import com.itbour.dto.trade.BuyTmplInfoDto;
import com.itbour.service.trade.BuyTmplService;
import com.opensymphony.xwork2.ActionContext;


/**
* 订单
* 
* copyright   itbour team 2017
* @author     xc
*
*/

public class BuyTmplServiceImpl implements BuyTmplService {

	private BuyTmplDao buyTmplDao;
	
	/**
	 * @param countKey
	 *            查询该表所有记录行的SQL语句ID
	 * @param sqlKey
	 *            需要查询记录的SQL语句ID
	 * @param param
	 *            传递给查询语句的参数
	 * @param pageNo
	 *            需要查询的实际页
	 * @param pageSize
	 *            每页记录行数
	 * @return page对象
	 */
	public Page buyPgQuery(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			
			// 实际起始位置
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = buyTmplDao.selectBuyCnt(param);
			
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<BuyTmplInfoDto> data = buyTmplDao.selectBuyInfo(param);

			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			//clearSelectDataSource(dataSource);
		}
	}

	public List<BuyTmplInfoDto> selectBuyInfo(Map<String,Object> param) {
		return buyTmplDao.selectBuyInfo(param);
	}

	public BuyTmplDao getBuyTmplDao() {
		return buyTmplDao;
	}

	public void setBuyTmplDao(BuyTmplDao buyTmplDao) {
		this.buyTmplDao = buyTmplDao;
	}

}
